let MyPromise = require('./04-MyPromise');
// let MyPromise = Promise;


// function p1() {
//     return new MyPromise(function (resolve, reject) {
//         setTimeout(function () {
//             resolve('p1')
//         }, 2000)
//     })
// }
// function p2() {
//     return new MyPromise(function (resolve, reject) {
//         reject('失败')
//         // resolve('成功');  
//     })
// }

// p2()
//     .then(value => console.log(value))
//     .catch(reason => console.log(reason))
// new MyPromise((resolve, reject) =>  { foo() ; resolve(566)}).then(res => console.log(res)).catch(console.log)

// const promise1 = MyPromise.resolve(3);
// const promise2 = new MyPromise((resolve, reject) => setTimeout(reject, 100, 'foo'));

// MyPromise.all([promise1, promise2]).then(res => console.log(res));

// const promise3 = new MyPromise((resolve, reject) => {
//     setTimeout(resolve, 500, 'one');
// });

// const promise4 = new MyPromise((resolve, reject) => {
//     setTimeout(resolve, 100, 'two');
// });

// Promise.race([promise3, promise4]).then((value) => {
//     console.log(value);
//     // Both resolve, but promise2 is faster
// });

// Promise.resolve(1)
//     .then(2)
//     .then(Promise.resolve(3))
//     .then(console.log)